package com.example.leetdemo.finash;

public class Solution537 {

    public String complexNumberMultiply(String num1, String num2) {
        String[] a = num1.replace("i", "").split("\\+");
        String[] b = num2.replace("i", "").split("\\+");
        if (a.length == 1) {
            a = new String[] {a[0], "1"};
        }
        if (b.length == 1) {
            b = new String[] {b[0], "1"};
        }
        StringBuilder stringBuilder = new StringBuilder();
        Integer p = Integer.parseInt(a[0]) * Integer.parseInt(b[0]) - Integer.parseInt(a[1]) * Integer.parseInt(b[1]);
        Integer q = Integer.parseInt(a[0]) * Integer.parseInt(b[1]) +
                Integer.parseInt(a[1]) * Integer.parseInt(b[0]);

        stringBuilder.append(p);
        stringBuilder.append("+");
        stringBuilder.append(q);
        stringBuilder.append("i");
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        Solution537 solution537 = new Solution537();
        System.err.println(solution537.complexNumberMultiply("1+i", "1+i"));
    }
}
